//
//  SubScrollView.m
//  Photograph
//
//  Created by TravelRound on 15/11/17.
//  Copyright © 2015年 TravelRound. All rights reserved.
//

#import "SubScrollView.h"

@implementation SubScrollView

- (void)dealloc
{
    [_imageV release];
    [super dealloc];
}

//- (instancetype)initWithFrame:(CGRect)frame index:(NSInteger)index
//{
//    self = [super initWithFrame:frame];
//    if (self) {
//        [self createSubviewsWithindex:index];
//    }
//    return self;
//}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

#warning 方式5 - layoutSubviews调用时机
- (void)layoutSubviews
{
    
    [super layoutSubviews];
    
    NSString *fileName = nil;
    
    if (0 == self.index) {
        fileName = @"image19.jpg";
    } else if (20 == self.index) {
        fileName = @"image1.jpg";
    } else {
        fileName = [NSString stringWithFormat:@"image%ld.jpg", self.index];
    }
    self.imageV.image = [UIImage imageNamed:fileName];
    
}

- (void)imageWithIndex:(NSInteger)index
{
    
    NSString *fileName = nil;
    if (0 == index) {
        fileName = @"image19.jpg";
    } else if (20 == index) {
        fileName = @"image1.jpg";
    } else {
        fileName = [NSString stringWithFormat:@"image%ld.jpg", index];
    }
    
    self.imageV.image = [UIImage imageNamed:fileName];
    
}

//- (void)setIndex:(NSInteger)index
//{
//    
//    NSString *fileName = nil;
//    if (0 == index) {
//        fileName = @"image19.jpg";
//    } else if (20 == index) {
//        fileName = @"image1.jpg";
//    } else {
//        fileName = [NSString stringWithFormat:@"image%ld.jpg", index];
//    }
//    
//    self.imageV.image = [UIImage imageNamed:fileName];
//    
//}

- (void)createSubviews
{
    
//    NSString *fileName = nil;
    
//    if (0 == self.index) {
//        fileName = @"image19.jpg";
//    } else if (20 == self.index) {
//        fileName = @"image1.jpg";
//    } else {
//        fileName = [NSString stringWithFormat:@"image%ld.jpg", self.index];
//    }
    
//    if (0 == index) {
//        fileName = @"image19.jpg";
//    } else if (20 == index) {
//        fileName = @"image1.jpg";
//    } else {
//        fileName = [NSString stringWithFormat:@"image%ld.jpg", index];
//    }
    
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
//    self.imageV.image = [UIImage imageNamed:fileName];
    [self addSubview:self.imageV];
    [_imageV release];
    
}

@end
